﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jinquantesthuiyuan_system
{
    public partial class Addhy : Form
    {
        public Addhy()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty && textBox2.Text == string.Empty && textBox3.Text == string.Empty && textBox4.Text == string.Empty && textBox5.Text == string.Empty)
            {
                MessageBox.Show("会员数据不能为空！");
                return;
            }
            //添加数据
            string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=huiyuan.accdb";//连接数据库
            try
            {
                OleDbConnection myconn = new OleDbConnection(str);
                myconn.Open();//打开数据库

                //string strinsert = "INSERT INTO jq_huiyuan(姓名，性别，年龄，会员号码，总余额，可用余额，创建时间，消费时间，手机号码) VALUES"
                string strInsert = "INSERT INTO `jq_huiyuan` (`user`, `phone`, `hpone`, `zye`, `kye`,`xje`, `xtime`) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')";
                strInsert = string.Format(strInsert, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text,textBox6.Text,textBox7.Text);

                OleDbCommand inst = new OleDbCommand(strInsert, myconn);
                int se = inst.ExecuteNonQuery();
                if(se != -1)//判断是否执行成功
                {
                    MessageBox.Show("添加成功！");
                    //添加成功后 执行刷新数据

                }

                myconn.Close();//关闭数据
                Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }
    }
}
